package com.demo.swingquickticket.swing.model;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;

public class AppJListModel extends AbstractListModel<String> {

    private List<String> data = new ArrayList<>();

    private List<String> searchData = new ArrayList<>();

    @Override
    public int getSize() {
        return searchData.size();
    }

    @Override
    public String getElementAt(int index) {
        return searchData.get(index);
    }

    public void setData(List<String> data) {
        setData(data, "");
    }

    public void setData(List<String> data, String searchStr) {
        this.data = data;
        setSearchData(searchStr);
    }

    public void setSearchData(String searchStr) {
        this.searchData.clear();
        if (searchStr.equals("")) {
            this.searchData.addAll(this.data);
        } else {
            for (String temp : this.data) {
                if (temp.contains(searchStr)) {
                    this.searchData.add(temp);
                }
            }
        }
    }
}
